Skip to content

FIX: ODBC Catalog method fetchone() issue#520

Open
jahnvi480 wants to merge 8 commits intomainfrom
jahnvi/fetchone_issue
Open

FIX: ODBC Catalog method fetchone() issue#520
jahnvi480 wants to merge 8 commits intomainfrom
jahnvi/fetchone_issue

Conversation

@jahnvi480
Copy link
Copy Markdown
Contributor

@jahnvi480 jahnvi480 commented Apr 14, 2026

Work Item / Issue Reference

AB#43996

GitHub Issue: #505


Summary

This pull request improves the reliability and correctness of catalog result set iteration in the mssql_python package. It ensures that the rownumber attribute is properly initialized for catalog queries, and adds comprehensive tests to verify that fetchone() and iteration work as expected for various catalog methods (such as tables, columns, primaryKeys, etc.).

Catalog result set iteration and row tracking improvements:

  • Ensured that the rownumber attribute is reset and properly initialized when fetching catalog results, so that fetchone() and iteration over catalog queries work correctly. (mssql_python/cursor.py)

Testing enhancements for catalog queries:

  • Added a suite of tests to verify that fetchone() and iteration work as expected for catalog-related cursor methods, including tables, columns, primaryKeys, foreignKeys, statistics, procedures, rowIdColumns, rowVerColumns, and getTypeInfo. These tests also verify that rownumber increments correctly and that no errors are raised when expected. (tests/test_004_cursor.py)
  • Added setup and cleanup test functions to create and remove test schemas and tables needed for catalog fetchone/iteration testing. (tests/test_004_cursor.py)

Copilot AI review requested due to automatic review settings April 14, 2026 08:34
@github-actions github-actions Bot added the pr-size: medium Moderate update size label Apr 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes fetchone()/cursor iteration failures on ODBC catalog result sets (e.g., tables(), columns(), etc.) by ensuring row-tracking state is initialized when preparing metadata result sets, and adds regression tests covering fetchone() and iteration across several catalog methods (GH-505 / AB#43996).

Changes:

  • Initialize catalog result-set row tracking by resetting cursor rownumber state in _prepare_metadata_result_set().
  • Add catalog-method regression tests for fetchone() and iterator behavior, plus rownumber increment assertions.
  • Add SQL setup/cleanup for catalog test objects (schema + tables with PK/FK).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
mssql_python/cursor.py Resets rownumber tracking when preparing catalog/metadata result sets so fetchone() and iteration treat them as active result sets.
tests/test_004_cursor.py Adds regression tests for catalog fetchone()/iteration + rownumber increments and introduces schema/table setup & cleanup for these tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mssql_python/cursor.py
Comment thread tests/test_004_cursor.py Outdated
Comment thread tests/test_004_cursor.py Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 14, 2026

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

79%


📈 Total Lines Covered: 6687 out of 8451
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/cursor.py (100%)

Summary

  • Total: 2 lines
  • Missing: 0 lines
  • Coverage: 100%

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 67.8%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 74.3%
mssql_python.pybind.connection.connection.cpp: 75.8%
mssql_python.__init__.py: 77.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 85.2%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

sumitmsft
sumitmsft previously approved these changes Apr 21, 2026
sumitmsft
sumitmsft previously approved these changes Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants